import { RecordType } from "@src/apps/activity/repositories/record.repository";
import {
  MAX_LINK_LENGTH,
  MAX_TITLE_LENGTH
} from "@src/apps/homepage/entities/nav-bar.entity";
import { isArray } from "@src/lib/decorators/conditions/array.condition";
import { isEnum } from "@src/lib/decorators/conditions/enum.condition";
import {
  inLength,
  isString
} from "@src/lib/decorators/conditions/string.condition";
import { isDate } from "@src/lib/decorators/conditions/time.condition";

export const isRawRecord = (parameter: any): boolean => {
  if (!("roomId" in parameter) || !isString(parameter.roomId)) {
    return false;
  }
  if (!("semesterId" in parameter) || !isString(parameter.semesterId)) {
    return false;
  }
  if (!("start" in parameter) || !isDate(parameter.start)) {
    return false;
  }
  if (!("end" in parameter) || !isDate(parameter.end)) {
    return false;
  }
  if (!("type" in parameter) || !isEnum(RecordType)(parameter.type)) {
    return false;
  }

  return true;
};

export const isNavBarColumn = (parameter: any): boolean => {
  if (!("title" in parameter) || !inLength(MAX_TITLE_LENGTH)(parameter.title)) {
    return false;
  }
  if (!("items" in parameter) || !isArray(parameter.items)) {
    return false;
  }
  for (const item of parameter.items) {
    if (!("title" in item) || !inLength(MAX_TITLE_LENGTH)(item.title)) {
      return false;
    }
    if (!("link" in item) || !inLength(MAX_LINK_LENGTH)(item.link)) {
      // TODO: verify link
      return false;
    }
  }

  return true;
};
